package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Teacher;

public class TeacherDao {
       static Teacher[] teacher=new Teacher[5];
       static {
           Teacher tea1=new Teacher("黑马001号","张飞","30","1990-01-01");
           Teacher tea2=new Teacher("黑马002号","李飞","40","1980-01-01");
           Teacher tea3=new Teacher("黑马003号","吴飞","50","1970-01-01");
           teacher[0]=tea1;
           teacher[1]=tea2;
           teacher[2]=tea3;
       }
    public static boolean addTeacher(Teacher tea) {
        int index=-1;
        for (int i = 0; i < teacher.length; i++) {
            if(teacher[i]==null){
                index=i;
                teacher[index]=tea;
                break;
            }
        }
        if(index==-1){
            return false;
        }else{
            return true;
        }
    }

    public static Teacher[] findAllTeacher() {
        return teacher;
    }

    public static Teacher[] quarryteacher() {
        return teacher;
    }

    public static void deleteTeacher(String sid) {
        int index = getIndex(sid);
        teacher[index]=null;
    }
    public static int getIndex(String sid){
           int index=-1;
        for (int i = 0; i < teacher.length; i++) {
            Teacher tea = TeacherDao.teacher[i];
            if(tea.getId().equals(sid)){
                index=i;
                break;
            }
        }
        return index;
    }

    public static void updataTeacher(Teacher tea, String sid) {
        int index = getIndex(sid);
        if(index!=-1){
            teacher[index]=tea;
        }
    }
}
